package com.hethongviet.job.helpers;


import com.hethongviet.job.AppMain;
import com.hethongviet.job.R;
import com.hethongviet.job.helpers.listadapter.ListItemDialogAdapter;
import com.hethongviet.job.pages.AddCommentActivity;
import com.hethongviet.job.pages.DetailTaskActivity;
import com.hethongviet.job.pages.MainActivity;

import android.app.Activity;
import android.app.Dialog;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class DialogList
{
	private Dialog _dialog = null;
	private ListView _listView = null;
	private Activity _activity = null;

	public DialogList(Activity activity)
	{
		_activity = activity;
		_dialog = new Dialog(activity);
		_dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		_dialog.setContentView(R.layout.dialog_list);
	}

	public void showDialog(String[] listItems, final int listType)
	{
		_listView = (ListView) _dialog.findViewById(R.id.listViewDialog);
		_listView.setAdapter(new ListItemDialogAdapter(_activity, listItems));
		_listView.setTextFilterEnabled(true);
		_listView.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id)
			{
				_dialog.hide();
				switch (listType)
				{
					case AppMain.DIALOG_ACCOUNT:
						AppMain.processDialogListAccount(_activity, position,
								_dialog);
						break;
					case AppMain.DIALOG_SORT_PROJECT:
						((MainActivity) _activity).processDialogListSortingProjects(position);
						break;
					case AppMain.DIALOG_SORT_TASK:
						((MainActivity) _activity).processDialogListSortingTasks(position);
						break;
					case AppMain.DIALOG_CHOOSING_IMAGE:
						if (_activity instanceof AddCommentActivity) ((AddCommentActivity) _activity).processDialogListChoosingImage(position);
						else if (_activity instanceof DetailTaskActivity) ((DetailTaskActivity) _activity).processDialogListChoosingImage(position);
						break;
					case AppMain.DIALOG_FILTER_TASK:
						((MainActivity) _activity).processDialogListFilteringTasks(position);
						break;
					case AppMain.DIALOG_FILTER_TASK_DELAY:
						((MainActivity) _activity).processDialogListFilteringTasksDelay(position);
						break;
					case AppMain.DIALOG_FILTER_COMMENT:
						((DetailTaskActivity) _activity).processDialogListSortingComment(position);
						break;

					default:
						break;
				}
			}
		});
		_dialog.show();
	}
	public void hide()
	{
		if(_dialog != null) _dialog.dismiss();
	}
}
